package com.asset.dispoal.business.bsCase.domain.db.mapper;

import com.asset.dispoal.business.appoint.dto.AppointInsertRequest;
import com.asset.dispoal.business.appoint.dto.CanAppointCaseRequest;
import com.asset.dispoal.business.appoint.dto.CanAppointCaseResponse;
import com.asset.dispoal.business.appoint.dto.QueryWithdrawlPageRequest;
import com.asset.dispoal.business.appoint.dto.QueryWithdrawlPageResponse;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.AgreementCaseState;
import com.asset.dispoal.business.bsAgreement.domain.db.entity.BsCaseAppointMapper;
import com.asset.dispoal.business.bsAgreement.dto.StateRecordResponse;
import com.asset.dispoal.business.bsCase.domain.db.entity.BsCase;
import com.asset.dispoal.business.bsCase.domain.db.entity.BsCaseDisposalFile;
import com.asset.dispoal.business.bsCase.domain.db.entity.BsCaseMediation;
import com.asset.dispoal.business.bsCase.domain.db.entity.CaseAgreement;
import com.asset.dispoal.business.bsCase.domain.db.entity.CaseIdCardNum;
import com.asset.dispoal.business.bsCase.domain.db.entity.CaseStateRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tech.mhuang.pacebox.springboot.protocol.data.Page;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author qr
 * @date 2022/4/7$
 */
@Mapper
public interface BsCaseMapper {

    /**
     * 批量添加
     *
     * @param caseList
     */
    void batchSaveBsCase(@Param("caseList") List<BsCase> caseList);

    /**
     * 分页查询
     *
     * @param page
     * @return
     */
    List<BsCase> queryBorrowerCaseByPage(@Param("request") Page<BsCase> page);

    /**
     * 条数查询
     *
     * @param bsCase
     * @return
     */
    int queryBorrowerCaseCount(@Param("request") BsCase bsCase);


    /**
     * 修改案件金额根据合同号
     *
     * @param agreementId
     */
    void updateCaseAmount(@Param("agreementId") String agreementId, @Param("bsCase") BsCase bsCase);


    BsCase getCaseById(String caseId);


    void batchOptBsCase(@Param("caseList") List<BsCase> collect);

    List<CaseIdCardNum> queryCaseIdNumByAssetInstBatchId(@Param("assetInstBatchId") String assetInstBatchId);

    Integer insertStateRecord(CaseStateRecord caseStateRecord);

    void updateCaseState(@Param("caseId") String caseId,
                         @Param("state") String waitDeliver,
                         @Param("complateState") String complateState,
                         @Param("userId") String userId);

    List<CaseAgreement> queryByAgreementId(@Param("assetInstBatchId") String assetInstBatchId,
                                           @Param("agreementIdList") List<String> agreementId);

    void batchDelCase(@Param("caseIdList") List<String> delCaseIdList);

    void batchStateRecord(@Param("recordList") List<CaseStateRecord> caseStateRecordList);

    List<StateRecordResponse> queryStateRecordById(@Param("caseId") String caseId);

    Integer deleteById(String caseId);

    void batchMapperDel(@Param("caseIdList") List<String> delCaseIdList);

    void batchDelRecord(@Param("caseIdList") List<String> delCaseIdList);

    Integer deleteRecordById(String caseId);

    List<AgreementCaseState> queryAgreementCaseStateByCaseId(@Param("caseId") String id);

    void insertMapping(@Param("agreementId") String agreementId, @Param("caseId") String caseId);

    void updateAmount(BsCase cases);

    void insert(@Param("item") BsCase cases);

    void subtraceAmount(BsCase cases);

    Integer updateIdCardState(@Param("caseId") String caseId,
                              @Param("idCardDate") String result,
                              @Param("caseIdCardState") String caseIdCardState);

    int queryCountCanAppointCase(CanAppointCaseRequest request);

    List<CanAppointCaseResponse> queryPageCanAppointCase(Page<CanAppointCaseRequest> page);

    List<String> queryCaseIdCanAppointCase(AppointInsertRequest request);

    Integer saveBathAppointMapper(@Param("mapperList") List<BsCaseAppointMapper> mapperList);


    Integer downloadOrder(BsCase bsCase);


    Integer updateState(@Param("caseId") String caseId,
                        @Param("userId") String userId,
                        @Param("state") String state,
                        @Param("merge") String merge);

    List<String> queryCaseIdByIdCardSetAndState(@Param("idCardSet") Set<String> idCardSet,
                                                @Param("state") String state,
                                                @Param("assetInstBatchId") String assetInstBatchId);

    Integer queryCountWithdrawal(QueryWithdrawlPageRequest request);

    List<QueryWithdrawlPageResponse> queryPageWithdrawal(Page<QueryWithdrawlPageRequest> page);

    void updateCaseStateResv(@Param("caseId") String caseId,
                             @Param("state") String waitDeliver,
                             @Param("complateState") String complateState,
                             @Param("userId") String userId);

    void insertDisposeFile(BsCaseDisposalFile caseDisposalFile);

    void insertDisposeFiles(@Param("fileList") List<BsCaseDisposalFile> fileList);

    void register(BsCase bsCase);

    void judgment(BsCase bsCase);

    void execution(BsCase bsCase);

    void mediation(BsCase bsCase);

    void insertMediation(BsCaseMediation caseMediation);

    void deleteMediationById(@Param("caseId") String id);

    List<Map<String, Object>> queryParamByParam(String actionKey);

    /**
     * 获取借款人户籍地址
     *
     * @return
     */
    List<BsCase> queryBorrowerAddress();

    /**
     * 批量更新行政编码
     *
     * @param collect
     */
    void batchAreaIdstBsCase(@Param("caseList") List<BsCase> collect);

    /**
     * 查询单条数据
     *
     * @param id
     * @return
     */
    BsCase queryById(String id);


    /**
     * 单条更新
     *
     * @param bsCase
     * @return
     */
    int update(BsCase bsCase);

    /**
     * 根据案件id更新案件还款状态
     *
     * @param caseId
     * @return
     */
    int updateRepaymentState(String caseId);

    Integer updateFormulaId(@Param("caseId") String id, @Param("formulaId") String formulaId);

    List<Map<String, String>> queryStatisticsByCode(@Param("code") String code);
}
